/*
* @Author: steven.wang
* @Date:   2019-01-09 17:36:50
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-05-15 10:40:52
*/
const PhotoModel = require('../../models/crawler/photo');
/**
 * 查询图片
 * @author steven.wang
 * @DateTime 2019-03-04T13:57:18+0800
 */
exports.list = async (req, res) => {
	req.query.sorts = req.query.sorts || 'createAt desc'
	let photos = await PhotoModel.list(req.query);
	let count = await PhotoModel.count(req.query);
	res.json({
		success: true,
		msg: '',
		data: {
			page: req.query.page || 1,
			pageSize: req.query.pageSize || 10,
			total: count[0]['count(*)'],
			list: photos
		}
	})
}
/**
 * 添加图片
 * @author steven.wang
 * @DateTime 2019-03-04T13:57:30+0800
 */
exports.addPhotos = async (req, res) => {
	let result = await PhotoModel.add(req.body);
	console.log(result)
	res.json({
		success: true,
		msg: ''
	})
}
/**
 * 更新图片
 * @author steven.wang
 * @DateTime 2019-03-04T13:57:48+0800
 */
exports.updatePhotos = async (req, res) => {
	let result = await PhotoModel.update(req.body);
	console.log(result)
	res.json({
		success: true,
		msg: ''
	})
}
/**
 * 删除图片
 * @author steven.wang
 * @DateTime 2019-03-04T13:57:54+0800
 */
exports.deletePhotos = async (req, res) => {
	let result = await PhotoModel.delete(req.body);
	console.log(result);
	res.json({
		success: true,
		msg: ''
	})
}